package org.s2015.testgdq.orm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Properties;

public class Access {
	public static int count = 0;
	
	public static void main(String args[]) {
		try {
			String db = "C:/Users/Administrator.PC-20130706PMHE/Desktop/MQ.MDB";
			String db2 = "C:/Users/Administrator.PC-20130706PMHE/Desktop/WIN2007.mdb";
			String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
					+ db;
			

			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

			Properties prop = new Properties(); // 只要添加这几句话就可以
			prop.put("charSet", "gb2312");

			Connection conn = DriverManager.getConnection(strurl, prop);
			Statement stmt = conn.createStatement();
//			ResultSet rs = stmt.executeQuery("select * from cjxx");
			ResultSet rs = stmt.executeQuery("select * from ganjian");
			ResultSetMetaData rsmd=rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			for (int i = 1; i <= columnCount ; i++) {
				System.out.print(rsmd.getColumnName(i)+"||");// 把列名存入向量heads中
			}
			System.out.println();
			if(rs.next()) {
				count++;
				String str = "";
				for(int a=1;a<columnCount+1;a++){
					str += rs.getString(a)+"||";
				}
				System.out.println(str);
			}
		} catch (Exception e) {
			System.out.println(e);
		}
		System.out.println(count);
	}

}